package bgpemulation;

import java.io.Serializable;

import bgpemulation.IPRoutingTable.MutableString;

public class IPRoutingTable extends CIDRMap<MutableString>{

	private static final long serialVersionUID = 1L;

	@Override
	public MutableString makeEntry(String value) {
		return new MutableString(value);
	}

	@Override
	public boolean updateValue(MutableString oldValue, String value) {
		if(oldValue.toString().equals(value)){
			return false;
		}
		oldValue.setString(value);
		return true;
	}
	
	@Override
	public boolean remove(CIDRPrefix p, String value) {
		MutableString nextHop = prefixes.get(p.getPrefixLength()).get(p);
		if(nextHop==null){
			return false;
		}
		if(nextHop.toString().equals(value)){
			delete(p);
		}
		return false;
	}
	
	@Override
	public void print(MutableString t) {
		System.out.println("\t" + t);
	}
	
	public class MutableString implements Serializable{

		private static final long serialVersionUID = 1L;
		private String str = null;
		
		public MutableString(String newStr){
			setString(newStr);
		}
		
		public void setString(String newStr){
			this.str = newStr;
		}
		
		@Override
		public String toString(){
			return str;
		}
	}

}
